using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;


public partial class ChiTietSanPham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
      
            int id = int.Parse(Request.QueryString["id"]);

            tbSanPhamEntities sanPham = tbSanPhamBUS.GetByID(id);
            lit_MaSP.Text = sanPham.MaSP.ToString();
            lit_TenSP.Text = sanPham.TenSP;
            lit_MoTa.Text = sanPham.MoTa;
            lit_DonGia.Text = sanPham.GiaBan.ToString();           
            lit_NgayCapNhat.Text =sanPham.NgayCapNhat.ToString("dd-MM-yyyy");
            lit_GiaGoc.Text = sanPham.GiaGoc.ToString();
            lit_SLBan.Text = sanPham.SLBan.ToString();
            lit_SoLuong.Text = sanPham.SLCon.ToString();


            tbLoaiSanPhamEntities LoaiSP = tbLoaiSanPhamBUS.GetByID(sanPham.MaLoai);
            lit_LoaiSP.Text = LoaiSP.TenLoai;

            int Total = 0;
            Criteria Cri = new Criteria();
            Cri.add(Condition.AND, tbHinhAnhEntities.tbHinhAnhEntitiesColumns.MaSP, Condition.EQUAL, sanPham.MaSP.ToString());
            tbHinhAnhEntities.tbHinhAnhEntitiesCollection hinhAnhCollection = tbHinhAnhBUS.Get(Cri.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize,
                                                                   tbHinhAnhEntities.tbHinhAnhEntitiesColumns.STT.ToString(),
                                                                     OrderDirection.ASC.ToString(), out Total);
            Repeater1.DataSource = hinhAnhCollection;
            Repeater1.DataBind();
            PagerV2_8_1.ItemCount = Total;
            if (PagerV2_8_1.ItemCount <= PagerV2_8_1.PageSize)
                PagerV2_8_1.Visible = false;
            else
                PagerV2_8_1.Visible = true;
       


    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbHinhAnhEntities hinhAnh = (tbHinhAnhEntities)e.Item.DataItem;           

            Image img_HinhAnh = (Image)e.Item.FindControl("img_HinhAnh");
            img_HinhAnh.ImageUrl = "~/Photos/Thumb/" + hinhAnh.HinhAnh.ToString();
        }
    }
}
